package com.yanqu.road.server.timer.zerotime;

import com.yanqu.road.server.manger.activity.dafuweng.DaFuWengMgr;
import com.yanqu.road.server.manger.player.PrivilegeCardMgr;
import com.yanqu.road.server.manger.scene.SceneMgr;
import com.yanqu.road.utils.LocalDateTimeHelper;
import com.yanqu.road.utils.executor.GeneralTask;

/**
 * 每日0点执行一次，服务器启动时也执行一次
 */
public class ZeroTimeTask extends GeneralTask {

    private long lastZeroTime = 0L;

    private boolean isRun = false;

    @Override
    public void doRun() {
        long zeroTime = LocalDateTimeHelper.getZeroTimeTimeStamp();
        if (lastZeroTime < zeroTime && !isRun) {
            isRun = true;

            // 年卡月卡过期提醒邮件
            try {
                PrivilegeCardMgr.checkSendExpireMail();
            } catch (Exception e) {
                getLOGGER().error("Privilege Card Expire Mail Task Error !!!");
                getLOGGER().error(e.getMessage());
            }

            // 大富翁清空旧数据
            try {
                DaFuWengMgr.cleanMemory();
            } catch (Exception e) {
                getLOGGER().error("DaFuWeng Clean Memory Task Error !!!");
                getLOGGER().error(e.getMessage());
            }

            // 场景清空旧数据
            try {
                SceneMgr.cleanOldData();
            } catch (Exception e) {
                getLOGGER().error("SceneMgr Clean Memory Task Error !!!");
                getLOGGER().error(e.getMessage());
            }
            lastZeroTime = zeroTime;
            isRun = false;
        }
    }

}
